<?php

namespace app\command;

use app\common\command\BaseCommand;
use app\model\home\Assistant;
use Curl\Curl;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\console\input\Option;
use libs\Log;

class MigrateAss extends BaseCommand
{
    protected function configure()
    {
        $this->setName('MigrateAss')
            ->addOption('test', 'a', Option::VALUE_NONE, 'this is a value_none option')
            ->addOption('required', null, Option::VALUE_REQUIRED, 'this is a value_required option')
            ->addOption('optional', null, Option::VALUE_OPTIONAL, 'this is a value_optional option')
            // 必选参数一定要在可选参数之前
            // ->addArgument('required', Argument::REQUIRED, "argument::required")
            ->addArgument('func', Argument::OPTIONAL, "argument::optional", 'test')
            ->setDescription('this is a description');
    }

    protected function execute(Input $input, Output $output)
    {
        $start = microtime(true);
        $curl = new Curl();
        $curl->get('http://175.24.182.131:8686/index.php/api/getUserInfo');
        $data = object_array($curl->response);
        $data = json_decode($data, true);
        foreach ($data['data'] as $item) {
            $list = [
                'nickname' => $item['name'],
                'store_id' => mt_rand(1, 2),
                'grade_id' => mt_rand(1, 4),
                'star' => mt_rand(1, 6)
            ];
            Assistant::create($list);
        }
        $end = microtime(true);
        $diff = $end - $start;
        echo "执行完毕，消耗时间为{$diff}s";
        $curl->close();

    }
}
